import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-05-15
 * Time: 17:12
 */
public class Test {
    public static void main(String[] args) {
        int[] array = new int[]{1,2,3,4,5,6,7,8,9,10};
        //for 循环-->数组对象.length获取数组长度
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
        //for each 循环-->遍历array数组将每个元素放入x中
        for (int x:array) {
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println("=====Arrays=====");
        //操作数组的工具类 Arrays
        String ret = Arrays.toString(array);
        System.out.print(ret + " ");
    }
    public static void main17(String[] args) {
        int[] array = new int[10];//动态初始化
        double[] array1 = new double[5];
        String[] array2 = new String[5];

        int[] array3 = new int[]{1,2,3,4,5};//静态初始化
        double[] array4 = new double[]{1.2,3.5,2.6,7.3};
        String[] array5 = new String[]{"ha","he","xi","nie"};

        int[] array6 = {5,4,3,2,1};//省略格式
        double[] array7 = {2.2,4.5,2.5,2.6};
        String[] array8 = {"hehe","haha","xixi","lolo"};

        int[] array9;
        array9 = new int[10];

        double[] array10;
        array10 = new double[]{1.2,3.2,5.3,6.33};

        //省略格式不可拆分
        /*String[] array11;
        array11 = {"haha","meiemi","hao","en"};
        int[] array12;
        array12 ={1,2,3,4,5};*/
    }

    public static void fuc3(int n) {
        if(n <10){
            System.out.print(n + " ");
            return;
        }
        fuc3(n/10);
        System.out.print(n%10 + " ");
    }

    public static void main16(String[] args) {
        //递归求 123 输出 1 2 3
        fuc3(123);
    }
    public static int fib1(int n) {
        int n1 = 1;
        int n2 = 1;
        int n3 = 0;
        for (int i = 3; i <= n; i++) {
            n3 = n1 + n2;
            n1 = n2;
            n2 = n3;
        }
        return n3;
    }
    public static void main15(String[] args) {
        System.out.println(fib1(10));
    }
    public static int fib(int n) {
        if( n == 1 || n == 2) {
            return 1;
        }
        return fib(n-1) + fib(n-2);
    }

    public static void main14(String[] args) {
        //递归求斐波那契数列--不建议用该方法
        int n = 10;
        System.out.println(fib(n));
    }
    public static int fuc2(int n) {
        if(n < 10) {
            return n;
        }
        return n % 10 + fuc2(n/10);
    }
    public static void main13(String[] args) {
        //3 写一个递归方法，输入一个非负整数，返回组成它的数字之和. 例如，输入 1729, 则应该返回
        //1+7+2+9，它的和是19
        int n = 1729;
        System.out.println(fuc2(n));
    }
    public static int fuc1(int n) {
        if(n == 1) {
            return 1;
        }
        return n + fuc1(n-1);
    }
    public static void main12(String[] args) {
        //递归求 1 + 2 + 3 + ... + 10
        System.out.println(fuc1(10));
    }
    public static int fuc(int n) {
        if(n == 1){
            return 1;
        }
        return n * fuc(n-1);
    }
    public static void main11(String[] args) {
        //递归求 N 的阶乘
        int N = 5;
        System.out.println(fuc(N));
    }
    public static int calc(int n) {
        int  mul= 1;
        for (int i = 1; i <= n ; i++) {
            mul *= i;
        }
        return mul;
    }
    public static void main10(String[] args) {
        //1! + 2! + 3! + 4! + 5!
        int sum = 0;
        for (int i = 1; i <= 5; i++) {
            sum += calc(i);
        }
        System.out.println(sum);
    }
    /*
    方法重载
    方法名相同
    参数类型不同，类型次序不同，参数个数不同
    与方法的返回类型是否相同无关
     */
    public static int add( int x, int y ) {
        return x + y;
    }
    public static double add(double x, double y) {
        return x + y;
    }
    public static double add(double x, double y, int z) {
        return x + y + z;
    }
    public static double add(double x, int z,double y) {
        return x + y + z;
    }

    public static void main9(String[] args) {
        int x = 15;
        int y = 20;
        int sum = add(x,y);
        System.out.println(sum);
    }

    public static boolean isLeapYear(int year) {
        if((year % 4 == 0 && year % 100 != 0) || year %400 == 0) {
            return true;
        }else {
            return false;
        }
    }
    public static void main8(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int year = scanner.nextInt();
        boolean ret = isLeapYear(year);
        if(ret == true) {
            System.out.println(year + "是闰年");
        }else {
            System.out.println(year + "不是闰年");
        }
    }
    public static void main7(String[] args) {
        // 获取一个数二进制序列中所有的偶数位和奇数位，分别输出二进制序列
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.print("奇数位：");
        for (int i = 31; i > 0; i-=2) {
            int ret1 = (n>>i) & 1;
            System.out.print(ret1 + " ");
        }
        System.out.println();
        System.out.print("偶数位：");
        for(int i = 30; i >= 0; i-=2) {
            int ret2 = (n>>i) & 1;
            System.out.print(ret2 + " ");
        }
    }
    public static void main6(String[] args) {
        //输出乘法口诀表
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(j + "*" + i + " = " + j * i +"  ");
            }
            System.out.println();
        }
    }
    public static void main5(String[] args) {
        //猜数字游戏
        Random random = new Random();
        int randomMum = random.nextInt(100);
        Scanner scanner = new Scanner(System.in);
        while(true) {
            System.out.println("请输入您要猜的数：");
            int scan = scanner.nextInt();
            if(scan == randomMum){
                System.out.println("找到了");
                break;
            }else if(scan > randomMum) {
                System.out.println("猜大了");
            }else {
                System.out.println("猜小了");
            }
        }
    }
    public static void main4(String[] args) {
        //使用 Scanner 循环读取 N 个数字，并求取其平均值
        int count = 0;
        int sum = 0;
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextInt()) {
            sum += scanner.nextInt();
            count++;
        }
        int aver = sum / count;
        System.out.println(aver);
    }
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("读入一个字符串：");
        String str = scanner.nextLine();
        System.out.println(str);
        System.out.println("读入一个整数：");
        int i = scanner.nextInt();
        System.out.println(i);//后有回车
        scanner.nextLine();//读取回车，让下面的代码正常输入，不然下面会直接输入输出回车
        System.out.println("读入一个字符串：");
        String str1 = scanner.nextLine();
        System.out.println(str1);
    }

    public static void main2(String[] args) {
        //多组输出 ctr+d终止
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()) {
            int n = in.nextInt();
        }
    }
    public static int sum (int n) {
        if(n < 10){
            return n;
        }
        return n%10 + sum(n/10);

    }
    public static void main1(String[] args) {
        System.out.println(sum(1729));
    }
}
